﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Power.Model;
using Power;
using Power.DAL;

namespace Admin.UI
{
    /// <summary>
    /// Editroot.xaml 的交互逻辑
    /// </summary>
    public partial class Editroot : Window
    {
        public string USername
        {
            get;
            set;
        }


        public Editroot()
        {
            InitializeComponent();
        }





        private void button1_Click(object sender, RoutedEventArgs e)
        {

            bool isOK = true;



            string usna = Usernamebox.Text;
            string password1 = passwordBox1.Password;
            string password2 = passwordBox2.Password;
            
           
            CheckPassboxNotEmpty(ref isOK, passwordBox1, passwordBox2);
            if (!isOK)
            {
                MessageBox.Show("有未填写信息");
                return;
            }
            if (password1!=password2)
            {
                MessageBox.Show("密码不一致");
                return;
            }


            User op = new User();
           op.UserName = usna;
            op.Password = CommonHelper.GetMD5(password1 + CommonHelper.GetPasswordSalt());
            op.Usertype = 0;
            op.IsDeleted = false;
            new UserDal().RootUpdatepass( op.UserName,op.Password);
            MessageBox.Show("修改成功");
            DialogResult = false;







        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Usernamebox.Text = USername;
            
        }






        private void CheckTextboxNotEmpty(ref bool isOK,
params TextBox[] textboxes)
        {
            foreach (TextBox txtBox in textboxes)
            {
                if (txtBox.Text.Length <= 0)
                {
                    isOK = false;
                    txtBox.Background = Brushes.Red;
                }
                else
                {
                    txtBox.Background = null;
                }
            }
        }

        private void CheckPassboxNotEmpty(ref bool isOK,
params PasswordBox[] passes)
        {
            foreach (PasswordBox passBox in passes)
            {
                if (passBox.Password.Length <= 0)
                {
                    isOK = false;
                    passBox.Background = Brushes.Red;
                }
                else
                {
                    passBox.Background = null;
                }
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

       


    }
}
